home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6064 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  61 lines

  1. Path: news.delphi.com!usenet
  2. From: JGUILLORY@delphi.com
  3. Newsgroups: comp.lang.c++
  4. Subject: U MUST READ THIS!!!!!
  5. Date: 11 Feb 1996 15:06:10 GMT
  6. Organization: Delphi Internet Services Corporation
  7. Message-ID: <4fl0l2$pl1@news1.delphi.com>
  8. References: <4epbn1$4hq@ixnews7.ix.netcom.com>
  9. NNTP-Posting-Host: bos1g.delphi.com
  10.  
  11.  
  12. Quoting jeremyx from a message in comp.lang.c++
  13.  je> Everyone keeps telling me not to use the "goto"
  14.  je> statement,they act like it's the plague! What is wrong with the goto
  15.  je> statement & what can i use in it's place?
  16.  
  17. Proper structured code needs no GOTO's eg: Consider the following:
  18. (untested)
  19.  
  20. #include <stdio.h>
  21.  
  22. void main(void) {
  23. FILE *f;
  24. label E1;
  25. char  command[]="DIR/W";
  26.  
  27.         f = fopen("TEST.BAT","wt");
  28.         if (f==NULL) goto E1;
  29.         fprintf(f,"%s\n",command);
  30.         fclose(f);
  31. E1:
  32. }
  33.  
  34. -- My syntax on the goto / Labels may be off, as I haven't used goto's
  35.    in C/C++ much.... (never needed them....)
  36.  
  37. The above could be simply re-written as:
  38.  
  39. #include <stdio.h>
  40.  
  41. void main(void) {
  42. FILE *f;
  43. char command[]="DIR/W";
  44.  
  45.         f = fopen("TEST.BAT","wt");
  46.         if (f!=NULL) {
  47.           fprintf(f,"%s\n",command);
  48.           fclose(f);
  49.         }
  50. }
  51.  
  52. Without GOTO's, you have 1 Start, and 1 Stop, and can write a flow-chart
  53. to match it very easily, with GOTO's you have 1 start, many stop's,
  54. and a big headache to look at it....
  55.  
  56. John H. Guillory
  57. JGuillory@Delphi.Com
  58.  
  59. Rainbow V 1.17.0 for Delphi - Test Drive
  60.  
  61.